<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
            3D化学后台管理系统
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="./css/x-admin.css" media="all">
    </head>
    
    <body style="background-color: #393D49">
        <div class="x-box">
            <div class="x-top">
                <i class="layui-icon x-login-close">
                    &#x1007;
                </i>
                <ul class="x-login-right">
                    <li style="background-color: #F1C85F;" color="#F1C85F">
                    </li>
                    <li style="background-color: #EA569A;" color="#EA569A">
                    </li>
                    <li style="background-color: #393D49;" color="#393D49">
                    </li>
                </ul>
            </div>
            <div class="x-mid">
                <div class="x-avtar">
                    <img src="./images/logo.png" alt="">
                </div>
                <div class="input">
                    <form class="layui-form">
                        <div class="layui-form-item x-login-box">
                            <label for="adminName" class="layui-form-label">
                                <i class="layui-icon">&#xe612;</i>
                            </label>
                            <div class="layui-input-inline">
                                <input type="text" id="adminName" name="adminName" required="" lay-verify="adminName"
                                autocomplete="off" placeholder="username" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item x-login-box">
                            <label for="pass" class="layui-form-label">
                                <i class="layui-icon">&#xe628;</i>
                            </label>
                            <div class="layui-input-inline">
                                <input type="password" id="password" name="password" required="" lay-verify="password"
                                autocomplete="off" placeholder="* * * * * *" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item" id="loginbtn">
                            <button class="layui-btn" lay-filter="save" lay-submit="">
                                登 录
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <p style="color:#fff;text-align: center;">Copyright © 2023.3D化学 All rights </p>
        <script src='./js/jquery.min.js' type='text/javascript' ></script>
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script src="./js/x-layui.js" charset="utf-8"></script>
        <script src="http-config.js"></script>
        <script>
            layui.use(['form'],
            function() {
                $ = layui.jquery;
                var form = layui.form(),
                layer = layui.layer;

                form.verify({
                    adminName: function(value){
                        if(value==null || value.length < 1){
                            return '登录名不能为空！';
                        }
                    },password: function(value){
                        if(value==null || value.length < 1){
                            return '密码不能为空！';
                        }
                    }
              });

                $('.x-login-right li').click(function(event) {
                    color = $(this).attr('color');
                    $('body').css('background-color', color);
                });

                //监听提交
                form.on('submit(save)',function(data) {
                    const adminName = $("#adminName").val();
                    const password = $("#password").val();
                    
                    $.ajax({
                        type: "POST",
                        url: baseURL +"/admin_info/verifyLogin",
                        data: JSON.stringify({"adminName":adminName, "password":password}),
                        contentType: "application/json",
                        success: function(data) {
                            console.log(data);
                            if(data.data.length==1 && data.data[0].adminRole=="超级管理员"){
                                location.href = "./index.html?adminRole=超级管理员";
                            }else{
                                location.href = "./index.html?adminRole=普通管理员";
                            }
                        },
                        error: function(xhr, status, error) {
                            console.error(error);
                        }
                    })
                    return false;
                });

            });

        </script>
    </body>

</html>